﻿@model Coslen.TahorCRM.Domain.Entities.ViewModels.Searching.ContactRelationshipSearchViewModel

@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Index</h2>

<p>
    @Html.ActionLink("Create New", "Create")
</p>
<table class="GenericTable fullWidth">
    <tr class="GenericTable-HeaderRow">
        <th>
            Relationship
        </th>
        <th>
            Primary Contact
        </th>
        <th>
            Secondary Contact
        </th>
        <th></th>
    </tr>

@foreach (var item in Model.SearchResults.Select((x, i) => new { Data = x, Index = i }))
{
    <tr class="@( item.Index % 2 == 0 ? "GenericTable-RowAlt" : "GenericTable-Row")">
        <td>
            @Html.DisplayFor(modelItem => item.Data.ContactRelationshipType.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Data.PrimaryContact.LastName), @Html.DisplayFor(modelItem => item.Data.PrimaryContact.Title.Name) @Html.DisplayFor(modelItem => item.Data.PrimaryContact.FirstName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Data.SecondaryContact.LastName), @Html.DisplayFor(modelItem => item.Data.SecondaryContact.Title.Name) @Html.DisplayFor(modelItem => item.Data.SecondaryContact.FirstName)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id = item.Data.ContactRelationId }) |
            @Html.ActionLink("Delete", "Delete", new { id = item.Data.ContactRelationId })
        </td>
    </tr>
}

</table>
